#include "maker_base.h"
// 没有分配堆内存
struct arp_pck arp_maker(uint8_t *sender_hardware_address, uint8_t *sender_protocol_address, uint8_t *target_hardware_address, uint8_t *target_protocol_address)
{
    struct ether_arp ether_arp;
    memcpy(&ether_arp.arp_sha[0], sender_hardware_address, ETH_ALEN);
    memcpy(&ether_arp.arp_spa[0], sender_protocol_address, 4);
    memcpy(&ether_arp.arp_tha[0], target_hardware_address, ETH_ALEN);
    memcpy(&ether_arp.arp_tpa[0], target_protocol_address, 4);
    ether_arp.ea_hdr.ar_op = 0x0100;
    ether_arp.ea_hdr.ar_pln = 4;
    ether_arp.ea_hdr.ar_hln = 6;
    ether_arp.ea_hdr.ar_hrd = 0x0100;
    ether_arp.ea_hdr.ar_pro = 0x0008;

    struct arp_pck pck = {
        .header.ether_dhost = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
        .header.ether_type = 0x0608,
        .arp = ether_arp,
    };
    memcpy(&pck.header.ether_shost[0], sender_hardware_address, ETH_ALEN);
    memset(&pck.fill_data[0], 0, 18);
    return pck;
}

struct arp_pck arp_maker_response(uint8_t *sender_hardware_address, uint8_t *sender_protocol_address, uint8_t *target_hardware_address,
                                  uint8_t *target_protocol_address)
{
    struct arp_pck pck = arp_maker(sender_hardware_address, sender_protocol_address, target_hardware_address, target_protocol_address);
    memcpy(pck.header.ether_dhost, target_hardware_address, 6);
    pck.arp.ea_hdr.ar_op = htons(2);
    return pck;
}